Ext.define('DutyList.calendar.dd.DropZonCalendarPanel',{
    extend: 'Ext.dd.DropZone',

    requires: [
        'Ext.Layer',
        'DutyList.calendar.util.Date',
        'DutyList.calendar.data.SheduleMappings'
    ],

    eventSelector: '.ext-cal-evt',

   getTargetFromEvent: function(e) {
       var el = Ext.get(e.getTarget(this.view.eventSelector,1)).findParent('.ext-cal-day-nighttime',3,true) || Ext.get(e.getTarget(this.view.eventSelector,1)).findParent('.ext-cal-day-daytime',3,true);
       return el ? this.view.getDateFromId(el.id) : null;
   },

    onNodeOver: function(n, dd, e, data) {
        var range = Ext.Date.format( Ext.Date.parse(n.startDate,'Ymd'), 'n/j'),
            msg = Ext.util.Format.format(this.moveText, range,(n.night ? 'night' : 'day'));
        data.proxy.updateMsg(msg);
        return this.dropAllowed;
    },

    onNodeDrop: function(n, dd, e, data) {
        var newStartDate = Ext.Date.parse(n.startDate,'Ymd'),
            newNight = n.night;
        if (n && data && DutyList.calendar.util.Date.compare(newStartDate, data.startDate) != 0) {
            if (data.type == 'eventdrag') {
                this.view.onCalendarEndDrag(newStartDate,newNight,data.ddel);
                return true;
            }
        }
        return false;
    }
});
